<template>
  <div class="bigBox bg-f2">
    <div class="bg-fff">
      <el-breadcrumb separator-class="el-icon-arrow-right" class="pAll">
        <el-breadcrumb-item>
          <span @click="goBack">运维日志</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ title }}</el-breadcrumb-item>
      </el-breadcrumb>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="pAll">
        <el-row>
          <!-- <el-col :span="2">
            <span class="title">添加业务日志：</span>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="今日完成工作:" prop="jrwcgz">
              <el-input v-model.trim="ruleForm.jrwcgz" clearable type="textarea" :rows="5" :maxlength="255" resize="none" show-word-limit placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="未完成工作:">
              <el-input v-model.trim="ruleForm.wwcgz" clearable type="textarea" :rows="5" :maxlength="255" resize="none" show-word-limit placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="需协调工作:">
              <el-input v-model.trim="ruleForm.xyxtgz" clearable type="textarea" :rows="5" :maxlength="255" resize="none" show-word-limit placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="备注:">
              <el-input v-model.trim="ruleForm.bz" clearable type="textarea" :rows="5" :maxlength="255" resize="none" show-word-limit placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="fooer_btn">
          <el-button size="medium" @click="quxiao" v-preventReClick class="btnSizeStyle">取消</el-button>
          <el-button size="medium" class="btnSizeStyle" type="primary" @click="baoCun(title, 'ruleForm')" v-preventReClick>保存</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import { yeWu } from '../../utils/allUrl.js'
import { getUrl } from '../../utils/getUrl.js'
export default {
  data() {
    return {
      title: '',
      ruleForm: {
        jrwcgz: '',
        wwcgz: '',
        xyxtgz: '',
        bz: '',
      },
      rules: {
        jrwcgz: [{ required: true, message: '此处为必填项', trigger: 'blur' }],
      },
    }
  },
  created() {
    const { title, content } = this.$route.query
    if (content) {
      this.setList(content)
    }
    this.title = title
  },
  methods: {
    goBack() {
      //  :to="{ path: '/journal' }"
      // this.$router.push('/JournalList')
      // 返回列表
      // this.$router.push({
      //   name: 'JournalList',
      //   params: {
      //     riqi: this.$route.query.riqi,
      //     nameList: this.$route.query.nameList,
      //   },
      // })
      this.$router.push({
        path: '/JournalList',
        params: {
          riqi: this.$route.query.riqi,
          nameList: this.$route.query.nameList,
        },
      })
    },
    async setList(id) {
      const params = new URLSearchParams()
      params.append('ID', id)
      const { data: res } = await this.$http.post(`${yeWu}ywrz/selectYeWuRiZhi`, params)
      switch (res.code) {
        case '0000':
          this.ruleForm = res.data.list[0]
          break
        default:
          this.ruleForm = []
          break
      }
    },
    baoCun(title, ruleForm) {
      const user = JSON.parse(getUrl('userconter'))
      const { jrwcgz, wwcgz, xyxtgz, bz, id } = this.ruleForm
      const params = new URLSearchParams()
      params.append('YH_ID', user.id)
      params.append('JRWCGZ', jrwcgz)
      params.append('WWCGZ', wwcgz)
      params.append('XYXTGZ', xyxtgz)
      params.append('BZ', bz)
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (title === '添加运维日志') {
            const { data: res } = await this.$http.post(`${yeWu}ywrz/insertYeWuRiZhi`, params)
            if (res.code === '0014') {
              return
            } else if (res.code !== '0000') {
              return this.$message({
                type: 'error',
                message: res.message,
                center: true,
              })
            }
            this.$message({
              type: 'success',
              message: res.message,
              center: true,
            })
            this.$router.push('/journal')
          } else {
            params.append('ID', id)
            const { data: res } = await this.$http.post(`${yeWu}ywrz/updateYeWuRiZhi`, params)
            if (res.code === '0014') {
              return
            } else if (res.code !== '0000') {
              return this.$message({
                type: 'error',
                message: res.message,
                center: true,
              })
            }
            this.$message({
              type: 'success',
              message: res.message,
              center: true,
            })
            this.$router.push('/journal')
          }
        } else {
          this.$message({
            type: 'error',
            message: '请填写正确的信息',
            center: true,
          })
          return false
        }
      })
    },
    quxiao() {
      this.$router.push('/journal')
    },
  },
}
</script>
<style lang="scss" scoped>
.bigBox {
  // padding: 20px 0;
  // .el-breadcrumb {
  //   height: 30px;
  //   border-bottom: 1px solid #e5e5e5;
  // }
  .el-row {
    // padding: 15px 25px 0 25px;
    border-bottom: 1px solid #e5e5e5;
    .title {
      display: block;
      height: 38px;
      line-height: 38px;
      color: rgba(89, 89, 89, 1);
      font-size: 15px;
      font-weight: 600;
    }
  }
  .fooer_btn {
    margin: 15px 0;
    display: flex;
    justify-content: flex-end;
  }
}
</style>
